using System.Collections;
using UnityEngine;

public class Enemy2 : TypeOfEnemy
{
	public void Init(int arrayNum)
	{
		arrayNumForAllObjectsInfo = arrayNum;
		SetEnemy();
		StopAllCoroutines();
		StartCoroutine(Motions());
		StartCoroutine(RefreshPosition());
		StartCoroutine(IE_Update());
		StartCoroutine(IE_DrawShadow());
		grabingWeaponID = 2;
		EquipGetOrDrop("Enemy", true, 1, grabingWeaponID);
		ChangeCharacterAnimType(GetKindOfWeaponNumber());
	}

	private IEnumerator Motions()
	{
		LookAtThePlayer();
		AppearJump();
		yield return new WaitForSeconds(2f);
		while (AllObjectsInfo.enemy[arrayNumForAllObjectsInfo].hp > 0f)
		{
			yield return new WaitForSeconds(0.1f);
			if (CheckAction())
			{
				continue;
			}
			if (freezingTime > 0f)
			{
				freezingTime -= 0.1f;
				continue;
			}
			LookAtThePlayer();
			if (PlayerInTheEnemyAttackZone(arrayNumForAllObjectsInfo) && Player.instance.hp > 0f && (SCRT_OnTheFloorSensor.onTheFloorFlag || tf.position.y > 3f) && Calc.IsVisibleCharacterOnScreen(tf.position))
			{
				kindOfMotion = 1;
				Attack();
			}
			else if (SCRT_OnTheFloorSensor.onTheFloorFlag)
			{
				if (Vector2.Distance(Player.instance.tf.position, AllObjectsInfo.enemy[arrayNumForAllObjectsInfo].pos) < Player.instance.hitSize + attackRange.x + 10f && Player.instance.tf.position.y > AllObjectsInfo.enemy[arrayNumForAllObjectsInfo].pos.y + 2f)
				{
					JumpToTheTarget();
				}
				else if (at.GetCurrentAnimatorStateInfo(0).IsName("StickMan_Idle") && Player.instance.hp > 0f)
				{
					at.CrossFade(running_NormalList[0], 0.1f);
				}
			}
			else if (at.GetCurrentAnimatorStateInfo(0).IsName("StickMan_Idle"))
			{
				currentOnTheFloorFlag = false;
				if (!attackingNow)
				{
					at.Play(jumping_NormalList[0], -1, 0f);
				}
			}
		}
	}
}
